/**
 * 
 */
package py.edu.ucom.cadira.net;

import java.util.ArrayList;

import org.jdom.Element;

/**
 * @author largonet
 * 
 */
public class User {
	protected String username;
	protected String nombre;
	private ArrayList<User> users;
    private static final String NODE_PLAYERS = "usuario";

	public User() {

	}

	public User(String username) {
		super();
		this.username = username;
	}

	public ArrayList<User> getUsers() {
		return users;
	}

	public void setUsers(User user) {
		users.add(user);
	}

	public String getNombre() {
		return nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof User)) {
			return false;
		}
        User otherObj = (User) obj;
		return username.equals(otherObj.getUsername());
	}

	@Override
	/**
	 * Como el username es unico para todos los usuarios. Utilizamos el username
	 * para hacer el hashing
	 */
	public int hashCode() {
		return username.hashCode();
	}

	@Override
	public String toString() {
		return username;
	}

	
	public Element toXml(){
		Element nodeUser=new Element(NODE_PLAYERS);
		Element nodeUsername=new Element("nombre");
		nodeUsername.addContent(getUsername());
		nodeUser.addContent(nodeUsername);
		return nodeUser; 
	}
    public User fromXml(Element userNode){
        Element nodeUsername = userNode.getChild("nombre");
        this.setUsername(nodeUsername.getValue());
        return this; 
    }
}
